/**   
 * @Title: MeetPriceServiceImpl.java 
 * @Package com.hanyong.admin.service.meetPrice 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author Li  
 * @date 2018年6月7日 上午11:15:30 
 * @version V1.0   
 */
package com.hyfrogx.modules.zoom.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hyfrogx.common.exception.MyException;
import com.hyfrogx.common.utils.RedisUtils;
import com.hyfrogx.modules.app.utils.FrogConstant;
import com.hyfrogx.modules.zoom.param.ZoomPirce;
import com.hyfrogx.modules.zoom.service.MeetPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/** 
 * @ClassName: MeetPriceServiceImpl 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author Li
 * @date 2018年6月7日 上午11:15:30 
 *  
 */
@Service(value = MeetPriceService.name)
public class MeetPriceServiceImpl implements MeetPriceService {
	
	static ZoomPirce zoomPirceObject = null;

	String meetprice = null;

	@Autowired
	RedisUtils redisUtils;

	@Override
	public void init() {
		//通过key获取对象
		meetprice = redisUtils.get(FrogConstant.RedisKey.FIX_PRICE);

		if(meetprice == null){
			ZoomPirce zoomPirce = new ZoomPirce();
			// 25方
			zoomPirce.setSmallTypeZero(0);
			zoomPirce.setSmallTypeOne(100);
			zoomPirce.setSmallTypeTwo(200);
			zoomPirce.setSmallTypeThree(300);
			zoomPirce.setSmallTypeFour(400);
			zoomPirce.setSmallTypeFive(500);
			zoomPirce.setSmallTypeSix(600);
			zoomPirce.setSmallTypeSeven(700);
			zoomPirce.setSmallTypeEight(800);
			zoomPirce.setSmallTypeEight(800);
			zoomPirce.setSmallTypeTen(900);
			zoomPirce.setSmallTypeEle(1000);
			// 50
			zoomPirce.setCenterTypeZero(0);
			zoomPirce.setCenterTypeOne(100);
			zoomPirce.setCenterTypeOne(100);
			zoomPirce.setCenterTypeTwo(200);
			zoomPirce.setCenterTypeThree(300);
			zoomPirce.setCenterTypeFour(400);
			zoomPirce.setCenterTypeFive(500);
			zoomPirce.setCenterTypeSix(600);
			zoomPirce.setCenterTypeSeven(700);
			zoomPirce.setCenterTypeEight(800);
			zoomPirce.setCenterTypeTen(900);
			zoomPirce.setCenterTypeEle(1000);
			// 100
			zoomPirce.setBigTypeZero(0);
			zoomPirce.setBigTypeOne(100);
			zoomPirce.setBigTypeTwo(200);
			zoomPirce.setBigTypeThree(300);
			zoomPirce.setBigTypeFour(400);
			zoomPirce.setBigTypeFive(500);
			zoomPirce.setBigTypeSix(600);
			zoomPirce.setBigTypeSeven(700);
			zoomPirce.setBigTypeEight(800);
			zoomPirce.setBigTypeTen(900);
			zoomPirce.setBigTypeEle(1000);
			// 500
			zoomPirce.setOversizeTypeZero(0);
			zoomPirce.setOversizeTypeOne(100);
			zoomPirce.setOversizeTypeTwo(200);
			zoomPirce.setOversizeTypeThree(300);
			zoomPirce.setOversizeTypeFour(400);
			zoomPirce.setOversizeTypeFive(500);
			zoomPirce.setOversizeTypeSix(600);
			zoomPirce.setOversizeTypeSeven(700);
			zoomPirce.setOversizeTypeEight(800);
			zoomPirce.setOversizeTypeTen(900);
			zoomPirce.setOversizeTypeEle(1000);
			// 200
			zoomPirce.setTwohundredTypeZero(0);
			zoomPirce.setTwohundredTypeOne(100);
			zoomPirce.setTwohundredTypeTwo(200);
			zoomPirce.setTwohundredTypeThree(300);
			zoomPirce.setTwohundredTypeFour(400);
			zoomPirce.setTwohundredTypeFive(500);
			zoomPirce.setTwohundredTypeSix(600);
			zoomPirce.setTwohundredTypeSeven(700);
			zoomPirce.setTwohundredTypeEight(800);
			zoomPirce.setTwohundredTypeTen(900);
			zoomPirce.setTwohundredTypeEle(1000);
			// 300
			zoomPirce.setThreeTypeZero(0);
			zoomPirce.setThreeTypeOne(100);
			zoomPirce.setThreeTypeTwo(200);
			zoomPirce.setThreeTypeThree(300);
			zoomPirce.setThreeTypeFour(400);
			zoomPirce.setThreeTypeFive(500);
			zoomPirce.setThreeTypeSix(600);
			zoomPirce.setThreeTypeSeven(700);
			zoomPirce.setThreeTypeEight(800);
			zoomPirce.setThreeTypeTen(900);
			zoomPirce.setThreeTypeEle(1000);
			redisUtils.set(FrogConstant.RedisKey.FIX_PRICE, zoomPirce);
			zoomPirceObject = zoomPirce;
		}else{
			JSONObject jsonObject  = JSONObject.parseObject(meetprice);
			zoomPirceObject = (ZoomPirce) jsonObject.toJavaObject(ZoomPirce.class);
		}
		editMeetPrice(zoomPirceObject);
	}

	@Override
	public Integer editMeetPrice(ZoomPirce zoomPirce) throws MyException {
		// TODO Auto-generated method stub
		zoomPirceObject = zoomPirce;
		redisUtils.set(FrogConstant.RedisKey.FIX_PRICE, zoomPirce);
		return 1;
	}

	@Override
	public Integer getMeetPriceByTime(String field) throws MyException {
		// TODO Auto-generated method stub
		JSONObject jsonObject  = JSONObject.parseObject(meetprice);
		int result = jsonObject.getInteger(field);
		return result;
	}

	@Override
	public ZoomPirce getMeetPriceObject() throws MyException {
		// TODO Auto-generated method stub
		return zoomPirceObject;
	}
	

}
